import { readLines } from "https://deno.land/std/io/bufio.ts";

export const regx = /([（|\(].*?[）|\)])/g

export function findFields(story: string) {
  const matches = story.matchAll(regx)
  return Array.from(matches, v => v[0]);
}

export function mapQuestion(field: string) {
  return `请填写${field}：`
}

export function mapQuestions(results: string[]) {
  return results.map(mapQuestion)
}
export function replaceSentence(story: string, res: string, replacer: string) {
  return story.replaceAll(res, replacer)
}

export async function question(question: string) {
  console.log(question);
  // Listen to stdin input, once a new line is entered return
  for await (const line of readLines(Deno.stdin)) {
    return line;
  }
}
